n = input().split()
b = {'zero': '0', 'one': '1', 'two': '2', 'three': '3', 'four': '4', 'five': '5', 'six': '6',
     'seven': '7', 'eight': '8', 'nine': '9'}


def prime(x):
    if x == 1:
        return False
    for i in range(2, int(x ** 0.5) + 1):
        if x % i == 0:
            return False
    return True


lst = ""
count = 0
for i in n:
    if i in '123456789':
        count = 1
if count == 1:
    print('Wrong input')
else:
    for j in n:
        lst = lst + b[j]
    lst = int(lst)
    count_1 = 0
    count_2 = 0
    k = lst
    while prime(k) == False:
        k = k + 1
        count_1 = count_1 + 1
    count_3 = lst
    while prime(count_3) == False:
        count_3 = count_3 - 1
        count_2 = count_2 + 1
    if count_1 <= count_2:
        print(k)
    else:
        print(count_3)